package com.goods.controller.business;

import com.goods.business.mapper.HealthMapper;
import com.goods.business.service.HealthService;
import com.goods.common.error.SystemException;
import com.goods.common.model.business.Health;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.system.PageVO;
import com.goods.system.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@Api(tags = "业务模块-物资资料相关接口")
@RestController
@RequestMapping("/business/health")
public class HealthController {

    @Autowired
    private UserService userService;
    @Autowired
    private HealthService healthService;
    @Autowired
    private HealthMapper healthMapper;

    @ApiOperation(value = "健康打卡提示")
    @GetMapping("/isReport")
    public ResponseBean isReport() throws SystemException {
        //获取用户ID
//        String username = userService.info().getUsername();

        String formatDate = new SimpleDateFormat("YYYY-MM-dd").format(new Date());
        Health health = healthMapper.findReport(formatDate);
        if (null != health){
            return ResponseBean.success(health);
        }
        return ResponseBean.success();
    }

    @ApiOperation(value = "立即打卡")
    @PostMapping("/report")
    public ResponseBean report(@RequestBody Health health) throws SystemException {
        healthService.report(health);
        return ResponseBean.success();
    }

    @ApiOperation(value = "签到记录查询")
    @GetMapping("/history")
    public ResponseBean report(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                               @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        PageVO<Health> healthPageVO = healthService.history(pageNum,pageSize);
        return ResponseBean.success(healthPageVO);
    }

}
